// import {Icomponent} from './'
import styles from './VersionSetting.module.css'

interface Icomponent {
    tempContainer: HTMLElement;
    init: () => void;
    template: () => void;
    handle: () => void;
}

interface Iversion {
    elem: string | HTMLElement;
    submit?: (val:string) => void;
}

function version(options: Iversion) {
    return new Version(options)
}

class Version implements Icomponent {
    tempContainer = document.createElement('div');

    constructor(private settings: Iversion) {
        this.init()
    }

    init() {
        this.template()
    }

    template() {
        this.tempContainer.className = styles.content;
        this.tempContainer.innerHTML = `
            <input class="${styles['version-input']}" placeholder="请输入"/>
            <button class="${styles['ok-button']}">确定</button>
        `
        this.settings.elem.appendChild(this.tempContainer)
    }

    handle() {
        const submitBtn = this.tempContainer.querySelector(`${styles['ok-button']}`);
        const inputDom = this.tempContainer.querySelector(`${styles['version-input']}`);
        submitBtn && submitBtn.addEventListener('click', () => {
            const inputValue = inputDom && inputDom.nodeValue;
            inputValue&&this.settings.submit&&this.settings.submit(inputValue);
        })
    }
}

export default version;